package com.xgq.drink.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xgq.drink.entity.ProductReview;
import com.xgq.drink.mapper.ProductReviewMapper;
import com.xgq.drink.service.IProductReviewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 商品评价表 服务实现类
 * </p>
 *
 * @author xgq
 * @since 2025-03-06
 */
@Service
public class ProductReviewServiceImpl extends ServiceImpl<ProductReviewMapper, ProductReview> implements IProductReviewService {
    @Override
    public void addReview(ProductReview review) {
        review.setCreatedAt(LocalDateTime.now());
        review.setStatus(1); // 默认状态为1（有效）
        review.setIsDeleted(0); // 默认未删除
        review.setFatherId(0L);
        save(review);
    }

    @Override
    public void deleteReview(Long reviewId) {
        removeById(reviewId);
    }

    @Override
    public QueryWrapper<ProductReview> getReviewsByProductId(Long productId) {
        QueryWrapper<ProductReview> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id", productId)
                .eq("is_deleted", 0); // 只查询未删除的评价
        return queryWrapper;
    }
}
